package com.syp.envops.util.sftp;

import java.util.List;

import com.jcraft.jsch.ChannelSftp.LsEntry;

public class ExtnameExcludeFilter implements Filter {

	private List<String> extnameExcludeList;

	public ExtnameExcludeFilter() {
	}

	public ExtnameExcludeFilter(List<String> extnameExcludeList) {
		this.extnameExcludeList = extnameExcludeList;
	}

	@Override
	public boolean doFilter(LsEntry le) {
		if (le.getFilename().equals(".") || le.getFilename().equals("..")) {
			return false;
		}
		if (le.getLongname().charAt(0) == 'd') {
			return true;
		}
		int extPointIndex = le.getFilename().lastIndexOf(".");
		if (extPointIndex < 0) {
			return true;
		}
		String extname = le.getFilename().substring(extPointIndex + 1);
		return extnameExcludeList.contains(extname);
	}

	public List<String> getExtnameExcludeList() {
		return extnameExcludeList;
	}

	public void setExtnameExcludeList(List<String> extnameExcludeList) {
		this.extnameExcludeList = extnameExcludeList;
	}

}
